angular.module('ted.mgt-service', [])
.factory('TedMgt',['$http', function($http){
    return {
        getTopics: function(callback){
            $http.get('/_api/mgt/topics').
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },       
        getTopic: function (id, callback) {
            $http.get('/_api/mgt/topic/'+id).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        getMenus: function(){
            return [
                {label:'首页', url:"/app/topic/hot",actived:true},
                {label:'往期回顾', url:"/app/topics"},
                {label:'管理入口', url:"/app/mgt/newtopic"},
            ];
        },
        getTopicByTag: function(tag,callback){
            $http.get('/_api/mgt/tag/'+tag).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        updateTopic: function(tid,jsonData,callback){
            $http.put('/_api/mgt/topic/'+tid, jsonData).
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        },
        getEnroll: function(tid,callback){
            $http.get('/_api/mgt/topic/'+tid+'/enroll').
                success(function(data, status, headers, config) {
                    callback(data);
                }).
                error(function(data, status, headers, config) {
                });
        }  

    };
}]);

